package com.fr.dialog.core;

import com.fr.base.Inter;
import com.fr.base.background.Background;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D.Double;
import javax.swing.JLabel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;

public class BackgroundPreviewLabel extends JLabel
{
  private Background background = null;
  private EventListenerList backgroundChangeListenerList = new EventListenerList();

  public BackgroundPreviewLabel()
  {
    setHorizontalAlignment(0);
  }

  public BackgroundPreviewLabel(Background paramBackground)
  {
    setBackgroundObject(paramBackground);
  }

  public void paintComponent(Graphics paramGraphics)
  {
    super.paintComponent(paramGraphics);
    if (getBackgroundObject() != null)
    {
      getBackgroundObject().paint(paramGraphics, new Rectangle2D.Double(0.0D, 0.0D, getSize().getWidth(), getSize().getHeight()));
      setText("");
    }
    else
    {
      setText(Inter.getLocText("Background-Background_is_NULL") + "...");
    }
  }

  public Background getBackgroundObject()
  {
    return this.background;
  }

  public void setBackgroundObject(Background paramBackground)
  {
    this.background = paramBackground;
    fireBackgroundStateChanged();
    repaint();
  }

  public void addBackgroundChangeListener(ChangeListener paramChangeListener)
  {
    this.backgroundChangeListenerList.add(ChangeListener.class, paramChangeListener);
  }

  public void fireBackgroundStateChanged()
  {
    Object[] arrayOfObject = this.backgroundChangeListenerList.getListenerList();
    ChangeEvent localChangeEvent = null;
    for (int i = arrayOfObject.length - 2; i >= 0; i -= 2)
      if (arrayOfObject[i] == ChangeListener.class)
      {
        if (localChangeEvent == null)
          localChangeEvent = new ChangeEvent(this);
        ((ChangeListener)arrayOfObject[(i + 1)]).stateChanged(localChangeEvent);
      }
  }
}